
import (Common) in "common";

map *skills      =([]);
map *bufs        =([]);
map *skillRefBuf =([]);

//
//map BUF_T=({
//    "WU_GONG":0,
//    "FA_GONG":1,
//    "XUAN_YUN":2,
//    "BING_DONG":3
//});
//
////输出参考
//map RESULT_REFER_T=({
//    "GONG_JI":0,
//    "FANG_YU":1,
//    "XUE_LIANG":2,
//    "NENG_LIANG":3
//});
//
//
//map RESULT_REFER_T=({
//    "GONG_JI":0,
//    "FANG_YU":1,
//    "XUE_LIANG":2,
//    "NENG_LIANG":3
//});
//
//
//
//
//map bufferDict = ([
//    ({
//        //buf编号
//        "bid":"1000000001",
//        "bufType":this.BUF_T["WU_GONG"],
//        "triggerOdds":100,
//        "resultType":1,//直接输出
//        //输出参考
//        "refTarget":this.RESULT_REFER_T["GONG_JI"],
//        //变化要求 1 增加 2 减少 3反弹
//        "changeType":1,
//        //变化类型 1百分比 2直接量
//        "changeValType":2,
//        //变量量
//        "changeVal":80
//    }),
//   ({
//        //buf编号
//        "bid":"1000000001",
//        "bufType":this.BUF_T["WU_GONG"],
//        "triggerOdds":100,
//        "resultType":1,//直接输出
//        //输出参考
//        "refTarget":this.RESULT_REFER_T["GONG_JI"],
//        //变化要求 1 增加 2 减少 3反弹
//        "changeType":1,
//        //变化类型 1百分比 2直接量
//        "changeValType":2,
//        //变量量
//        "changeVal":80
//    })
//]);

void test_bt(){




    //队员数据结构
    map tMember = ({
        //头顶要显示的文字
        "tip":"",
        "name":"张三丰",
        "hp":100,
        "maxHp":100,
        "qi":100,
        "maxQi":100,
        //是否是队长
        "leader":0,
        //站位
        "pos":0
    });

    map tMember1 = ({
        //头顶要显示的文字
        "tip":"",
        "name":"逍遥子",
        "hp":100,
        "maxHp":100,
        "qi":100,
        "maxQi":100,
        //是否是队长
        "leader":0,
        //站位
        "pos":0
    });


    //甲方队员数据
    //乙方

    //甲方数据
    map fa = ({
        //队员
        "members":([tMember])
    });

   map fb = ({
       //队员
       "members":([tMember1])
   });

   //所有队伍数据
}

void pk(var fa,var fb){

   //谁先出手
   map *teams = ([]);

   int ridx=0;
   bool isEnd = false;
   for(; !isEnd ; ){
       println(ridx);

   }


}




void main(string* args)  {

     this.skills         = readExcelSkills();
     this.bufs           = readExcelBuffers();
     this.skillRefBuf    = readSkillRefBuf();
     map sk =  getSkillData(100001);
     println(toJsonStr(sk));
}


map getSkillData(int skillId){


    map *skills         = this.skills;
    map *bufs           = this.bufs;
    map *skillRefBuf    = this.skillRefBuf;
//    int skillId = 100001;
    map skillData = ({});
    //找出skill数据
    for(int i; i < skills.size();i++){
        if( skills[i]["sid"]==skillId ){
            skillData = skills[i];
            break;
        }
    }
    //找出Buf数据
    int *bufIds = ([]);

    for(int i; i < skillRefBuf.size();i++){
        if( skillRefBuf[i]["sid"]==skillId ){
            bufIds+=skillRefBuf[i]["buf_id"];
            break;
        }
    }

    //找buf
    map *bufDatas = ([]);

    for(int i; i < bufIds.size(); i++){
        for( int j; j < bufs.size();j++){
             if( bufs[j]["buf_id"] == bufIds[i] ){
                bufDatas+=bufs[j];
                continue;
             }
        }
    }

    //skillData["buf"] is array
    skillData["buf"] = bufDatas;

    return skillData;
}

map* readExcelSkills(){
        var xlsData = readExcel("","J技能表",1,0);
        map keyData = ({});
        map *resData = ([]);
        int i=0;
        foreach(d in xlsData){
           if(i==0){
             for(int j; j < d.size() ; j++){
                 if( d[j]=="" ) continue;
                 keyData[j] = d[j];
             }
           }else{

            var resUnitData = ({});
            string *headerNames = values(keyData);
             foreach( hn in headerNames){
                resUnitData[hn]="";
             }
             for(int j; j < d.size() ; j++){
                 if(nonep(d[j])) continue;
                 if( nonep(keyData[j]) ) continue;
                   resUnitData[keyData[j]] = d[j];
             }
             resData+=resUnitData;
           }
           i++;
        }

       return resData;
}


map* readExcelBuffers(){

        var xlsData = readExcel("","J技能BUF表",6,0);
        map keyData = ({});
        map *resData = ([]);

        int i=0;
        foreach(d in xlsData){
           if(i==0){
             for(int j; j < d.size() ; j++){
                 if( !d[j] ) continue;
                 keyData[j] = d[j];
             }
             //在此处构造好结构，等之后的数据填充

           }else{
             var resUnitData = ({});
             string *headerNames = values(keyData);
             foreach( hn in headerNames){
                resUnitData[hn]="";
             }
             for(int j; j < d.size() ; j++){
                 if(nonep(d[j])) continue;
                 if( nonep(keyData[j]) ) continue;
                 resUnitData[keyData[j]] = d[j];
             }
             resData+=resUnitData;
           }
           i++;
        }
        return resData;
}



//技能和buf关联数据
map* readSkillRefBuf(){

        var xlsData = readExcel("","J技能和BUF关联表",4,0);
        map keyData = ({});
        map *resData = ([]);

        int i=0;
        foreach(d in xlsData){
           if(i==0){
             for(int j; j < d.size() ; j++){
                 if( !d[j] ) continue;
                 keyData[j] = d[j];
             }
             //在此处构造好结构，等之后的数据填充

           }else{
             var resUnitData = ({});
             string *headerNames = values(keyData);
             foreach( hn in headerNames){
                resUnitData[hn]="";
             }
             for(int j; j < d.size() ; j++){
                 if(nonep(d[j])) continue;
                 if( nonep(keyData[j]) ) continue;
                 resUnitData[keyData[j]] = d[j];
             }
             resData+=resUnitData;
           }
           i++;
        }
       return resData;
}
